<template>
	<view>
		<view class="kefuInfo" v-if="kefu!=null">
			<view><image class="avator" :src="wechatKefuQrcode"></image></view>
		</view>
		<view  class="kefuDesc">
			<view>1. 绑定微信请扫描或识别上面二维码</view>
			<view>2. 如果不想接收信息，微信公众号右上角，设置中可设置消息免打扰</view>
			<view>3. 解除绑定可点击下面按钮，解除后该微信OpenID将收不到消息推送</view>
		</view>

		<uni-list v-show="wechatList.length!=0">
			<uni-list-item v-for="v in wechatList" :key="v.id"  
			:show-extra-icon="true" 
			:extra-icon="wechatIcon" 
			clickable 
			@click="unBindWechat(v.oauth_id)" 
			:title="'微信解绑 '+v.oauth_id" ></uni-list-item>
		</uni-list>
	</view>

</template>

<script>
	import toolsHelper from '../../common/tools.js';
	export default {
		data() {
			return {
				kefu:null,
				token:"",
				baseUrl:"",
				wechatKefuQrcode:"",
				wechatIcon:{color: '#3b4144',size: '22',type: 'weixin'},
				wechatList:[],
			}
		},
		// 页面显示
		onShow() {
			let _this = this;
			let res = uni.getStorageSync('app');
			if (res) {
				this.token = res.token;
			}
			let domainInfo = uni.getStorageSync('domain');
			if (domainInfo) {
				this.baseUrl = domainInfo.domain;
			}
			this.kefuInfo();
		},
		methods: {
			kefuInfo() {
				var _this = this;
				uni.request({
					url: _this.baseUrl + '/kefu/kefuinfo?token=' + _this.token,
					method: 'get',
					header: {
						'Content-Type': 'application/x-www-form-urlencoded'
					},
					success: function(res) {
						_this.kefu=res.data.result;
						_this.callBack();
					}
				});
			},
			callBack(){
				var _this=this;
				uni.request({
					url: _this.baseUrl + '/wechat/showQrcode',
					data:{entId:_this.kefu.ent_id,sceneName:"kf_"+_this.kefu.name},
					method: 'get',
					header: {
						'token': _this.token
					},
					success: function(res) {
						_this.wechatKefuQrcode=res.data.result.url;
						_this.getOpenid();
					}
				});
				
			},
			getOpenid(){
				var _this=this;
				uni.request({
					url: _this.baseUrl + '/kefu/wechatOpenidList',
					method: 'get',
					header: {
						'token': _this.token
					},
					success: function(res) {
						_this.wechatList=res.data.result;
					}
				});
			},
			unBindWechat(openId){
				var _this=this;
				uni.request({
					url: _this.baseUrl + '/kefu/delWechatOpenid',
					data:{oauth_id:openId},
					method: 'get',
					header: {
						'token': _this.token
					},
					success: function(res) {
						_this.getOpenid();
					}
				});
			}

		}
	}
</script>

<style>
	page{
				background-color: #eef0f6;
	}
	.kefuInfo{
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	.kefuDesc{
		padding: 20px;
		font-size: 14px;
		color: #333;
		line-height: 23px;
	}
	.kefuInfo .avator{
		margin-top: 20px;
		width: 300px;
		height: 300px;
	}
</style>